<template>
  <div class="containerRow right-container-width">
    <aside class="h1 rest-tab">
      {{ $t('restaurant.allRestaurant') }}
      <div class="underline" />
    </aside>
    <div class="rest-container">

      <Shopinfo
        v-for="item in shopListFilter"
        :key="item._id"
        :item="item"
      />
    </div>
  </div>
</template>

<script>
import moment from 'moment-timezone';
import _ from 'lodash';
import { mapState, mapActions } from 'vuex';
import Shopinfo from '@/views/restaurant/components/shopinfo/Shopinfo.vue';

export default {
  components: { Shopinfo },
  computed: {
    ...mapState({
      shopList: (state) => state.restaurant.list,
    }),

    //* 过滤数组 */
    shopListFilter() {
      // *将数组进行排序 // featured   zscore 排序
      const shopListNew = _.orderBy(this.shopList, ['featured', 'zscore'], ['desc', 'desc']);

      const openShop = [];
      const closeShop = [];

      shopListNew.forEach((item) => {
        const usday = (moment().tz(item.timezone).day() + 1); // 显示周几
        const ushour = moment().tz(item.timezone).hour() * 60;
        const usminute = moment().tz(item.timezone).minute();
        // console.log('usday', usday);

        // console.log(item.hours);
        // item.hours.forEach((element) => {
        //   console.log('element.dayOfWeek', element.dayOfWeek);
        // });

        if (item.closed !== true) { //* 先判断是否close，再判断是否是在开门的时间，直接就是获得美国的时间进行对比
          if (ushour + usminute >= item.hours[6].start
                && ushour + usminute <= item.hours[usday].end) {
            openShop.push(item);
          } else {
            closeShop.push(item);
          }
        } else {
          closeShop.push(item);
        }
      });
      // console.log(openShop.concat(closeShop));
      return openShop.concat(closeShop);
    },
  },

  created() {
    this.hideUserUnflod();
    this.getRestaurant();
  },

  updated() {
    window.scroll(0, 0);
  },

  methods: {
    ...mapActions([
      'getRestaurant',
      'hideUserUnflod',
    ]),

  },

};
</script>

<style>

</style>
